function citylist(el, elBox) {
    this._init(el, elBox);
    $("."+elBox+" .city").empty();
    $("."+elBox+" .level").empty();
    $("."+elBox+" .provinceList").empty();
}
citylist.prototype = {
    _init: function (el, elBox) {
        //创建数组
        var provinceArray = new Array();
        var cityArray = new Array();
        var levelDataName = new Array();
        var levelBoxList = new Array();
        var jishennum = new Array();
        var cityList;
        $("#"+el+"").val('保山市,普洱市,临沧市,文山壮族苗族,楚雄彝族,西双版纳傣族,昭通市,德宏傣族景颇族,迪庆藏族,怒江傈僳族,克拉玛依市,伊犁哈萨克,昌吉回族,巴音郭楞蒙古,阿勒泰地区,塔城地区,哈密市,吐鲁番市,喀什地区,阿克苏地区,博尔塔拉蒙古,和田地区,克孜勒苏柯尔克孜,拉萨市,林芝市,日喀则市,昌都市,那曲地区,阿里地区,山南市,广元市,达州市,广安市,自贡市,凉山彝族,雅安市,巴中市,攀枝花市,资阳市,甘孜藏族,阿坝藏族羌族,汉中市,延安市,安康市,商洛市,铜川市,长治市,忻州市,晋城市,吕梁市,阳泉市,朔州市,莱芜市,海东市,海西蒙古族藏族,海南藏族,海北藏族,玉树藏族,黄南藏族,果洛藏族,吴忠市,中卫市,石嘴山市,固原市,乌兰察布市,锡林郭勒盟,巴彦淖尔市,乌海市,兴安盟,阿拉善盟,葫芦岛市,本溪市,铁岭市,辽阳市,阜新市,朝阳市,鹰潭市,景德镇市,萍乡市,新余市,四平市,白山市,白城市,辽源市,张家界市,湘西土家族苗族,荆门市,鄂州市,随州市,恩施土家族苗族,黑河市,伊春市,双鸭山市,绥化市,鸡西市,鹤岗市,大兴安岭地区,七台河市,三门峡市,鹤壁市,儋州市,三沙市,六盘水市,黔西南布依族苗族,梧州市,钦州市,百色市,贵港市,防城港市,河池市,崇左市,来宾市,贺州市,云浮市,酒泉市,天水市,定西市,张掖市,陇南市,平凉市,庆阳市,白银市,武威市,嘉峪关市,金昌市,甘南藏族,临夏回族,池州市,淮北市,北京市,镇江市,扬州市,盐城市,泰州市,淮安市,连云港市,宿迁市,芜湖市,蚌埠市,铜陵市,阜阳市,滁州市,漳州市,莆田市,宁德市,珠海市,汕头市,江门市,揭阳市,湛江市,肇庆市,潮州市,桂林市,柳州市,遵义市,海口市,三亚市,唐山市,廊坊市,邯郸市,沧州市,邢台市,秦皇岛市,洛阳市,商丘市,信阳市,南阳市,许昌市,新乡市,驻马店市,大庆市,宜昌市,襄阳市,荆州市,黄冈市,岳阳市,株洲市,衡阳市,湘潭市,常德市,吉林市,上饶市,赣州市,九江市,宜春市,鞍山市,呼和浩特市,包头市,银川市,西宁市,临沂市,济宁市,淄博市,威海市,菏泽市,咸阳市,绵阳市,德阳市,曲靖市,湖州市');
        Array.prototype.remove = function (val) {
            var index = this.indexOf(val);
            if (index > -1) {
                this.splice(index, 1);
            }
        };

        //点击模态框显示下拉列表
        $("."+elBox+" .province-sl").click(function () {
            $("."+elBox+" .provinceList").toggle();
            $("."+elBox+" .city").empty();
            $("."+elBox+" .level").empty();
            $("."+elBox+" .provinceList").empty();
            jishennum = $("#"+el+"").val().split(',');
            //ajax渲染省列表
            var loading = '<li class=\'loading\'>加载中...</li>';
            $("."+elBox+" .provinceList").append(loading);
            $.ajax({
                type: "get",
                contentType: "application/json; charset=utf-8",
                url: './city.json',
                success: function (data) {
                    for(var i = 0; i < data.length; i++) {
                        var provinceName = data[i].provinceName;
                        var ifLevelCity = data[i].ifLevel;
                        var levelCityList;
                        provinceArray[i]=provinceName;
                        var provinceData = '';
                        var textVal = $("#"+el+"").val().split(',');
                        if(ifLevelCity) {
                            levelCityList = data[i].level[provinceName][0];
                            levelBoxList.push(levelCityList);
                            provinceData += "<li data-index="+i+" data-name="+provinceName+"><input class=\"cheValue\" data-name="+levelCityList+" type='checkbox' />"+provinceName+"</li>";
                        } else {
                            provinceData += "<li data-index="+i+" data-name="+provinceName+"><input class=\"cheValue\" data-name="+provinceName+" type='checkbox' />"+provinceName+"</li>";
                        }
                        $("."+elBox+" .provinceList").append(provinceData);
                        $.each(textVal, function (i,dom){
                            $("."+elBox+" :checkbox[data-name='"+dom+"']").prop("checked",true);
                            $('.loading').hide();
                        });
                    }
                    var textareaVal = $("#"+el+"").val();
                    for(var k in levelBoxList) {
                        if(textareaVal.indexOf(levelBoxList[k]) != -1) {
                            var str = levelBoxList[k].join(',');
                            $("."+elBox+" :checkbox[data-name='"+str+"']").prop("checked",true);
                        }
                    }
                }
            });
        });
        //点击省显示城市层级（几线城市）
        $("."+elBox+" .provinceList").on('click', 'li', function (e) {
            $("."+elBox+" .city").empty();
            $("."+elBox+" .level").empty();
            $(this).addClass('activeCity').siblings().removeClass('activeCity');
            var index = $(this).attr('data-index');
            var provinceName = provinceArray[index];
            $.ajax({
                type: "get",
                contentType: "application/json; charset=utf-8",
                url: './city.json',
                success: function (data) {
                    for(var n=0; n < data.length; n++) {
                        var provice = data[n];
                        if (provice.provinceName == provinceName) {
                            cityList = provice.level;
                            var levelData = '';
                            $.each(cityList, function (key, value) {
                                cityArray = cityList;
                                var dataName = value[0];
                                levelDataName.push(dataName);
                                levelData += "<li data-name=" + key + "><input class=\"cheValue\" data-name=" + dataName + " type='checkbox' />" + key + "</li>";
                            });
                        }
                    }
                    $("."+elBox+" .level").append(levelData);
                    var textVal = $("#"+el+"").val();
                    for(var h in levelDataName) {
                        var levelOk = levelDataName[h];
                        if(textVal.indexOf(levelOk) != -1){
                            var str = levelOk.join(',');
                            $("."+elBox+" :checkbox[data-name='"+str+"']").prop("checked",true);
                        }
                    }
                }
            });
        });
        //点击城市层级显示城市
        $("."+elBox+" .level").on('click', 'li', function (e) {
            $("."+elBox+" .city").empty();
            $(this).addClass('activeCity').siblings().removeClass('activeCity');
            var text = $(this).attr('data-name');
            $.ajax({
                type: "get",
                url: './city.json',
                success: function (data) {
                    var cityList =new Array();
                    for(var j in cityArray) {
                        cityList = cityArray[text];
                    }
                    for(var m = 1; m < cityList.length; m++) {
                        var cityData = '';
                        var cityValue = cityList[m].cityName;
                        cityData += "<li><input class=\"cheValue\" data-name="+cityValue+" type='checkbox' />"+cityList[m].cityName+"</li>";
                        var textVal = $("#"+el+"").val().split(',');
                        $("."+elBox+" .city").append(cityData);
                    }
                    $.each(textVal, function (i,dom){
                        $("."+elBox+" :checkbox[data-name='"+dom+"']").prop("checked",true);
                    });
                }
            });
        });
        $("#removeBtn").click(function () {
            $('.province ul li').remove();
            // $(".provinceList").hide();
        });
        //复选按钮
        $('.'+elBox+'').on('click', '.cheValue', function(e) {
            var textareaDataList = $(this).attr("data-name").split(',');
            if($(this).is(':checked')) {
                $.each(textareaDataList, function (addIndex, data) {
                    jishennum.push(data);
                });
            } else {
                $.each(textareaDataList, function (removeIndex, data) {
                    jishennum.remove(data);
                });
            }
            $("#"+el+"").val(jishennum);
        });
    }
};